package edu.calvin.djs32.cs214.interpreters.prettyprinter;

import edu.calvin.cs214.hobbes2008.ApplicationTIR;
import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.HobbesTIRVisitor;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;

public class PrettyPrinter implements HobbesTIRVisitor<String>{

	private String computeCssClass(int i) {
		return ((i >= 0) ? "integer" : "integer negative");
	}

	public String interpret(HobbesTIR tir) {
		return "<pre>" + tir.accept(this) + "</pre>";
	}

	public String visitInteger(IntegerTIR integerTIR) {
		int i = integerTIR.getInt();
		return "<span class=\"" + computeCssClass(i) + "\">" + i + "</span>";
	}

	public String visitApplication(ApplicationTIR application) {
		return null;
	}

	public String visitString(StringTIR string) {
//		String string1 = string.getString();
//		int stringLength = string1.length();
//		string1 = string1.substring(1,stringLength-1);
		return "<span class=\"string\">&lsquo;" + string + "&rsquo;</span>";
	}

	public String visitTuple(TupleTIR tuple) {
		final String tupleSpan = "<span class=\"tuple\">(";
		final String tupleSpanClose = ")</span>";
		String tupleReturn = "";
		for (int i = 0; i < tuple.getLength(); i++) {
			tupleReturn += tuple.getElement(i).accept(this);
			if (i == (tuple.getLength()-1) ){
				
			}else{
				tupleReturn += ", ";
			}
		}
		return tupleSpan + tupleReturn + tupleSpanClose;
	}

}
